package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    /**
     * 新增床位
     *
     * @param bedDto
     * @return
     */
    @PostMapping("/create")
    @ApiOperation(value = "新增床位", notes = "传入房间id")
    public ResponseResult addBed(@RequestBody BedDto bedDto) {


        return toAjax(bedService.addBed(bedDto));

    }

    /**
     * 根据id删除床位
     *
     * @param id 床位id
     * @return 删除的记录条数
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "根据id删除床位", notes = "传入房间id")
    public ResponseResult deleteBed(@PathVariable("id") Long id) {
        return toAjax(bedService.deleteBedById(id));
    }

    /**
     * 更新床位
     *
     * @param bedDto
     * @return
     */
    @PutMapping("/update")
    public ResponseResult updateBed(@RequestBody BedDto bedDto) {

        return toAjax(bedService.updateBed(bedDto));
    }

    /**
     * 根据床位id查询床位
     *
     * @param id
     * @return
     */
    @GetMapping("/read/{id}")
    @ApiOperation(value = "根据床位id查询床位", notes = "传入床位id")
    public ResponseResult readBed(@PathVariable("id") Long id) {

        return toAjax(bedService.selectBedById(id));
    }


}
